home *** CD-ROM | disk | FTP | other *** search
- /* ----------------------------------------------------------------------
-
- Progress CDEF
- version 1.3.2
-
- Written by: Paul Celestin
-
- Copyright © 1993-1997 Celestin Company, Inc.
-
- This CDEF displays a very simple progress thermometer.
-
- 930927 - 1.0.0 - initial release
- 931012 - 1.0.1 - bug fixes
- 940320 - 1.0.2 - more bug fixes
- 951215 - 1.3.0 - updated for CW7
- 960704 - 1.3.1 - updated for CW9
- 970815 - 1.3.2 - updated for CW Pro 1
-
- ---------------------------------------------------------------------- */
-
- #include <Types.h>
- #include <Memory.h>
- #include <Quickdraw.h>
- #include <Fonts.h>
- #include <ToolUtils.h>
- #include <Icons.h>
- #include <Controls.h>
- #include <Gestalt.h>
-
- /* ----------------------------------------------------------------------
- prototypes
- ---------------------------------------------------------------------- */
- pascal long main(short, ControlHandle, short, long);
- void drawIt(ControlHandle, short);
-
-
- /* ----------------------------------------------------------------------
- main
- ---------------------------------------------------------------------- */
- pascal long main(short variation, ControlHandle theControl, short message, long param)
- {
- long returnValue = 0L;
- char state = HGetState((Handle)theControl);
- Str255 copyright = "\pCopyright © 1993-1996 Celestin Company, Inc.";
-
- switch(message)
- {
- case drawCntl:
- drawIt(theControl,variation);
- case testCntl:
- break;
- case calcCRgns:
- break;
- case initCntl:
- break;
- case dispCntl:
- break;
- case posCntl:
- break;
- case thumbCntl:
- break;
- case dragCntl:
- break;
- case autoTrack:
- break;
- case calcCntlRgn:
- break;
- case calcThumbRgn:
- break;
- default:
- break;
- }
-
- HSetState((Handle)theControl,state);
-
- return(returnValue); /* tell them what happened */
- }
-
-
- /* ----------------------------------------------------------------------
- drawIt - here is where we actually draw the control
- ---------------------------------------------------------------------- */
- void drawIt(ControlHandle control, short variation)
-
- {
- Rect myRect;
- PenState oldPenState;
- int myValue = GetCtlValue(control),
- myMax = GetCtlMax(control),
- myMin = GetCtlMin(control),
- myColor,
- width = 0,
- range = 100;
-
- if (!(*control)->contrlVis) /* if not visible, do nothing */
- return;
-
- GetPenState(&oldPenState); /* save off current environment */
-
- myRect = (*control)->contrlRect; /* define our control rect */
-
- PenNormal(); /* make pen normal */
-
- FrameRect(&myRect); /* draw border around the control */
- InsetRect(&myRect,1,1);
-
- ForeColor(whiteColor);
- BackColor(whiteColor);
- PaintRect(&myRect);
-
- width = myRect.right - myRect.left; /* width in pixels of the control */
- range = myMax - myMin;
-
- if (range < 10) range = 10; /* to deal with screwy ranges */
-
- myRect.right = myRect.left + (myValue * width) / range;
-
- switch (GetCRefCon(control))
- {
- case 1:
- myColor = redColor;
- break;
- case 2:
- myColor = greenColor;
- break;
- case 3:
- myColor = blueColor;
- break;
- case 4:
- myColor = cyanColor;
- break;
- case 5:
- myColor = magentaColor;
- break;
- case 6:
- myColor = yellowColor;
- break;
- case 7:
- myColor = whiteColor;
- break;
- default:
- myColor = blackColor;
- break;
- }
-
- ForeColor(myColor);
- BackColor(myColor);
- PaintRect(&myRect);
-
- ForeColor(blackColor);
- BackColor(whiteColor);
- SetPenState(&oldPenState); /* restore the original environment */
-
- return; /* we are done drawing */
- }
-